//
//  CustomerServiceViewController.m
//  LubanWork
//
//  Created by xiaotong on 2020/1/3.
//  Copyright © 2020 xiaohao. All rights reserved.
//

#import "CustomerServiceViewController.h"

@interface CustomerServiceViewController (){
    UILabel *labe1;
    UILabel *labe2;
}
@property(nonatomic,copy) NSString * qqNumber;
@property(nonatomic,copy) NSString * telNumber;
@property(nonatomic,copy) NSString * wxNumber;
@property(nonatomic,copy) NSString * email;
@end

@implementation CustomerServiceViewController
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"联系客服";
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"services"]];
    imageView.userInteractionEnabled = YES;
    [self.view addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(kSCRATIO(4));
        make.left.equalTo(self.view).offset(kSCRATIO(25));
        make.right.equalTo(self.view).offset(-kSCRATIO(25));
        make.height.mas_offset(kSCRATIO(155));
    }];
    
    
    UIView *backView1 = [[UIView alloc] init];
    backView1.userInteractionEnabled = YES;
    [self.view addSubview:backView1];
    [backView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imageView.mas_bottom).offset(kSCRATIO(21));
        make.left.equalTo(self.view).offset(kSCRATIO(20.5));
        make.right.equalTo(self.view).offset(-kSCRATIO(20.5));
        make.height.mas_offset(kSCRATIO(80));
    }];

    backView1.backgroundColor = kColorFromRGBHex(0xFFFFFF);
    
    backView1.layer.shadowOffset = CGSizeMake(0, 0);
    backView1.layer.shadowRadius = 4;
    backView1.layer.shadowOpacity = 4;
    backView1.layer.shadowColor = [UIColor colorWithRed:1/255.0 green:6/255.0 blue:29/255.0 alpha:0.1].CGColor;
    backView1.layer.cornerRadius = kSCRATIO(8);
    
    UIImageView *iconImage1 = [[UIImageView alloc] init];
    iconImage1.userInteractionEnabled = YES;
    iconImage1.image = [UIImage imageNamed:@"email"];
    [backView1 addSubview:iconImage1];
    
    [iconImage1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backView1);
        make.left.equalTo(backView1).offset(kSCRATIO(10.5));
        make.width.mas_offset(kSCRATIO(39));
        make.height.mas_offset(kSCRATIO(34));
    }];
    
    UIView *lineView1 = [[UIView alloc] init];
    lineView1.userInteractionEnabled = YES;
    lineView1.backgroundColor = kColorFromRGBHex(0xD7D4D4);
    
    [backView1 addSubview:lineView1];
    
    [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(kSCRATIO(1));
        make.height.mas_offset(kSCRATIO(40));
        make.centerY.equalTo(backView1);
        make.left.equalTo(iconImage1.mas_right).offset(kSCRATIO(10.5));
    }];
    
    
    UILabel *label1 = [UILabel CreatLabeltext:@"官方客服邮箱" Font:kFONT(17) Textcolor:kColorFromRGBHex(0x1C1B1B) textAlignment:NSTextAlignmentLeft];
    label1.userInteractionEnabled = YES;
    [backView1 addSubview:label1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineView1);
        make.left.equalTo(lineView1).offset(kSCRATIO(14.5));
        make.height.mas_offset(kSCRATIO(20));
        make.right.equalTo(backView1.mas_right).offset(-kSCRATIO(20));
    }];
    
    labe1 = [UILabel CreatLabeltext:@"xxx@xx.xx" Font:kFONT(14) Textcolor:kColorFromRGBHex(0x7F7E7E) textAlignment:NSTextAlignmentLeft];
    labe1.userInteractionEnabled = YES;
    [backView1 addSubview:labe1];
    [labe1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(lineView1.mas_bottom);
        make.left.equalTo(lineView1).offset(kSCRATIO(14.5));
        make.height.mas_offset(kSCRATIO(14));
        make.right.equalTo(backView1.mas_right).offset(-kSCRATIO(20));
    }];
    [backView1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyEmail)]];
    [labe1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyEmail)]];

    [label1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyEmail)]];
    [iconImage1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyEmail)]];
    
    UIView *backView2 = [[UIView alloc] init];
    backView2.userInteractionEnabled = YES;
    [self.view addSubview:backView2];
    [backView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backView1.mas_bottom).offset(kSCRATIO(21));
        make.left.equalTo(self.view).offset(kSCRATIO(20.5));
        make.right.equalTo(self.view).offset(-kSCRATIO(20.5));
        make.height.mas_offset(kSCRATIO(80));
    }];

    backView2.backgroundColor = kColorFromRGBHex(0xFFFFFF);
    
    backView2.layer.shadowOffset = CGSizeMake(0, 0);
    backView2.layer.shadowRadius = 4;
    backView2.layer.shadowOpacity = 4;
    backView2.layer.shadowColor = [UIColor colorWithRed:1/255.0 green:6/255.0 blue:29/255.0 alpha:0.1].CGColor;
    backView2.layer.cornerRadius = kSCRATIO(8);
    
    UIImageView *iconImage2 = [[UIImageView alloc] init];
    iconImage2.userInteractionEnabled = YES;
    iconImage2.image = [UIImage imageNamed:@"qqkf"];
    [backView2 addSubview:iconImage2];
    
    [iconImage2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backView2);
        make.left.equalTo(backView2).offset(kSCRATIO(10.5));
        make.width.mas_offset(kSCRATIO(39));
        make.height.mas_offset(kSCRATIO(34));
    }];
    
    UIView *lineView2 = [[UIView alloc] init];
    lineView2.userInteractionEnabled = YES;
    lineView2.backgroundColor = kColorFromRGBHex(0xD7D4D4);
    
    [backView2 addSubview:lineView2];
    
    [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_offset(kSCRATIO(1));
        make.height.mas_offset(kSCRATIO(40));
        make.centerY.equalTo(backView2);
        make.left.equalTo(iconImage2.mas_right).offset(kSCRATIO(10.5));
    }];
    
    
    UILabel *label2 = [UILabel CreatLabeltext:@"官方客服QQ" Font:kFONT(17) Textcolor:kColorFromRGBHex(0x1C1B1B) textAlignment:NSTextAlignmentLeft];
    label2.userInteractionEnabled = YES;
    [backView2 addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineView2);
        make.left.equalTo(lineView2).offset(kSCRATIO(14.5));
        make.height.mas_offset(kSCRATIO(20));
        make.right.equalTo(backView2.mas_right).offset(-kSCRATIO(20));
    }];
    
    labe2 = [UILabel CreatLabeltext:@"8888888" Font:kFONT(14) Textcolor:kColorFromRGBHex(0x7F7E7E) textAlignment:NSTextAlignmentLeft];
    labe2.userInteractionEnabled = YES;
    [backView2 addSubview:labe2];
    [labe2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(lineView2.mas_bottom);
        make.left.equalTo(lineView2).offset(kSCRATIO(14.5));
        make.height.mas_offset(kSCRATIO(14));
        make.right.equalTo(backView2.mas_right).offset(-kSCRATIO(20));
    }];
    [backView2 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(iconClick)]];
    [labe2 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(iconClick)]];

    [label2 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(iconClick)]];
    [iconImage2 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(iconClick)]];
}
-(void)loadData{
    __weak __block typeof(self) weakSelf=self;
    [[NetWorkManager sharedManager] getJSON:@"api/cs/contacts" parameters:@{@"type":@(1)} success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([UtilTools isBlankDictionary:responseObject[@"result"]]) {
            return;
        }
        if (![UtilTools isBlankString:responseObject[@"result"][@"contactNumber"]]) {
            weakSelf.qqNumber=responseObject[@"result"][@"contactNumber"];
            dispatch_async(dispatch_get_main_queue(), ^{
                labe2.text=weakSelf.qqNumber;
            });
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    [[NetWorkManager sharedManager] getJSON:@"api/cs/contacts" parameters:@{@"type":@(5)} success:^(NSURLSessionDataTask *task, id responseObject) {
        if ([UtilTools isBlankDictionary:responseObject[@"result"]]) {
            return;
        }
        if (![UtilTools isBlankString:responseObject[@"result"][@"contactNumber"]]) {
            weakSelf.email=responseObject[@"result"][@"contactNumber"];
            dispatch_async(dispatch_get_main_queue(), ^{
                labe1.text=weakSelf.email;
            });
        }
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}
-(void)copyEmail{
    if ([UtilTools isBlankString:self.email]) {
        return;
    }
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string=self.email;
    [HWProgressHUD showMessage:@"邮箱已复制"];
}
-(void)iconClick{
    if ([UtilTools isBlankString:self.qqNumber]) {
        return;
    }
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string=self.qqNumber;
    [HWProgressHUD showMessage:@"QQ号已复制3秒后打开QQ"];
    dispatch_after(dispatch_time_delay(3), dispatch_get_main_queue(), ^{
        if ([UtilTools haveQQ]) {
             NSURL * url = [NSURL URLWithString:@"mqq://"];
                    [[UIApplication sharedApplication] openURL:url options:nil completionHandler:^(BOOL success) {
                        
                    }];
        }else{
             [HWProgressHUD showMessage:@"未安装QQ"];
        }
    });
}

@end
